Future squirels battle for food scraps near homeless man’s dome tent
To battle these savage beasts, we must learn to make our own light sabor.
set.seed(1.1)
light_sabor_length <- 20
number_of_animal_sabors_in_a_park <- 5000
distance_between_transects <- 40.1
point_1 <- c(-(light_sabor_length/2),(light_sabor_length/2))
point_2 <- c(0,0)
single_sabor <-cbind(point_1, point_2)
rownames(single_sabor)<- c("point_1","point_2")
colnames(single_sabor)<- c("x","y")
single_sabor
## x y
## point_1 -10 0
## point_2 10 0
Then distribute the army of sabor-wielding critters across the landscape.
First we rotate around the origin to set the instantanious angle of each animal’s individual sabor.
angle <- runif(1, min=1, max=360)*pi/180
xy <- as.matrix(single_sabor)
# Rotation
cos.angle <- cos(angle)
sin.angle <- sin(angle)
after_rotation <- xy %*% t(matrix(c(cos.angle, sin.angle, -sin.angle,
cos.angle), 2, 2))
after_rotation
## [,1] [,2]
## point_1 1.100398 -9.939272
## point_2 -1.100398 9.939272
Then we move (a.k.a. translate) the sabor to a location on the landscape where the critter is located. We assume that all the critters are battling vigously and indescriminintly with each other so they are randomly distributed across space and the angles of all the sabors are uniformly distributed.
# Translation
translation.x <- runif(1, min=10, max=90)
translation.y <- runif(1, min=10, max=90)
translation <- matrix(
c(translation.x,translation.x,translation.y,translation.y), 2, 2)
new_coord <- after_rotation + translation
colnames(new_coord) <- c("x","y")
rownames(new_coord) <- c("Point_1","Point_2")
Repeat for an entire box of matches
critter_sabor <- function(){
single_sabor <-cbind(c(-5,5),c(0,0))
angle <- runif(1, min=1, max=360)*pi/180
xy <- as.matrix(single_sabor)
# Rotation
cos.angle <- cos(angle)
sin.angle <- sin(angle)
after_rotation <- xy %*% matrix(c(cos.angle, sin.angle, -sin.angle,
cos.angle), 2, 2, byrow=TRUE )
# Translation
translation.x <- runif(1, min=10, max=90)
translation.y <- runif(1, min=10, max=90)
translation <- matrix(
c(translation.x,translation.x,translation.y,translation.y), 2, 2)
new_coord <- after_rotation + translation
colnames(new_coord) <- c("x","y")
rownames(new_coord) <- c("Point_1","Point_2")
return(new_coord)
}
critter_sabor()
## x y
## Point_1 21.93899 84.59096
## Point_2 30.33012 79.15139
for(i in 1:number_of_animal_sabors_in_a_park){
critter_sabor()
}
surface_line <- function(line_height = 0){
matrix(c(0,100,line_height,line_height), 2, 2, byrow=FALSE)
}
## [,1] [,2]
## [1,] 0 20
## [2,] 100 20
one_sabor <- critter_sabor()
one_surface_line <- surface_line(30)
line.line.intersection(one_sabor[1,], one_sabor[2,], one_surface_line[1,],
one_surface_line[2,], interior.only = TRUE)
## [1] 75.73794 30.00000